<?php

/**
 * Classes form.
 *
 * @package    elearning
 * @subpackage form
 * @author     Your name here
 */
class ClassesForm extends BaseClassesForm
{
  public function configure()
  {
	  // an 2 cot "created_at" va "updated_at"
	  unset($this['created_at'], $this['updated_at']);
	  
	  // check box : cls_status
	  $classes = $this->getObject();
		if( $classes->getClsStatus() == 0 )
			$classes->setClsStatus(NULL);
	  $this->widgetSchema['cls_status'] = new sfWidgetFormInputCheckbox(array("value_attribute_value" => 1),array('value' => 1));	
	  $this->validatorSchema['cls_status'] =  new sfValidatorInteger( array('required' => false ));
  
  	  // so sanh ngay bat dau va ngay ket thuc
	  $this->validatorSchema->setPostValidator( new sfValidatorOr( array (
        new sfValidatorAnd( array (
          new sfValidatorSchemaCompare ('cls_start_time', sfValidatorSchemaCompare::NOT_EQUAL, null ), 
          new sfValidatorSchemaCompare ('cls_end_time', sfValidatorSchemaCompare::EQUAL, null )
        )) ,
 	       new sfValidatorSchemaCompare('cls_start_time', sfValidatorSchemaCompare::LESS_THAN_EQUAL, 'cls_end_time',array('throw_global_error' 		=> false), array('invalid' => 'The start date ("%left_field%") must be before the end date ("%right_field%")' ))
    )));
  
  
  //add fields multi languages
  $lang_current = sfContext::getInstance()->getUser()->getCulture();
	$this->languages = array($lang_current => $lang_current);
	$langs = array_keys($this->languages);
	$this->embedI18n($langs);
	foreach($this->languages as $lang => $label)
	{
	  $this->widgetSchema[$lang]->setLabel($label);
	}
  }
}
